//
//  AppDelegate+SinglePart.m
//  DS_PJ_01
//
//  Created by admin on 16/8/17.
//  Copyright © 2016年 zhiqiyun. All rights reserved.
//

#import "AppDelegate+SinglePart.h"

@implementation AppDelegate(SinglePart)


-(void)loadCodesOnlyAppDelegate:(id)rootViewController
{
    self.window =  [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    self.window.backgroundColor = [UIColor whiteColor];
    
    //PS:关于这里,曾经遇到过一次问题(已经忘记),如果出现一些莫名其妙的错误,可以把代码顺序进行交换.
    self.window.rootViewController = rootViewController;
    
    [self.window makeKeyAndVisible];
    
}


-(BOOL)setFirstLaunchingApp
{
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    
    if (![user objectForKey:@"FirstLaunchingApp"]) {
        
        [user setObject:@(YES) forKey:@"FirstLaunchingApp"];
        
        NSAssert(![user synchronize],
                 @"[user setObject:@(YES) forKey:FirstLaunchingApp] -- failure");
        
        [self launchGuideView];
        
        
        [self launchUserGuide];
    }
    
    
    
    return YES;
}


//开启引导图
-(void)launchGuideView
{
    NSAssert(1, @"Please write code here,about guide view,and deleting mine codes");
    
    /*
     PS:一般而言,引导图是改变rootViewController.设置步骤如下
        1,新建一个UIViewController,例如名叫 DSGuideViewController
     
        2,实例DSGuideViewController *vc,并且在里面做引导图内容,增加一个返回block
     
        3,[self.window setRootViewController:vc];

        block例子:
        DSGuideViewController.h
        typedef void(^sSuccessBlock)();
     
        //在这里实现block;
        vc.sSuccessBlock =^() {
            NSLog(@"引导图结束,设置rootViewController为首页");
            
            //实例首页homeViewController
            [self.window setRootViewController:homeViewController];
     
        }
     
    */
    
}

//开启用户指南 --- 一般首次安装App会调用
-(void)launchUserGuide
{
    
    UIWindow *userGuide = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    NSLog(@"%@",[userGuide class]);
    
    //获取所有的window
//    NSArray *windows = [UIApplication sharedApplication].windows;
    
    //调用以下方法才会显示window   : window makeKeyAndVisible
    
    //移除Window   :
    /*
     [window resignKeyWindow];
     _thisAlertWindow = nil;
     */

    
}


//加载个性化设置
-(void)loadSetting
{
    //设置状态栏颜色
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        /*
         info.plist 增加一个节点 View controller-based status bar appearance
         BOOL类型,设置为NO
         */
        
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
        
        // 使用图片给导航栏附加颜色
        [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_color"] forBarMetrics:UIBarMetricsDefault];
        
        if (IOS7_LATER) {
            [[UINavigationBar appearance] setTranslucent:NO];
        }
        
        
        // 直接附加颜色
//        [[UINavigationBar appearance] setBarTintColor:[UIColor grayColor]];
        
        // 设置导航栏字体颜色
        [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName]];
    }

}


@end
